<?php 
	
	class Offhours_model extends CI_Model {
		
		var $tblName = "offhours_days";
		 
		function __construct()
		{
			parent::__construct();
		}
		
		function save($record, $id)
		{	
			$id = (int)$id;
			if( $id > 0 ) 
			{
				$this->db->where('id', $id);
				$this->db->update($this->tblName, $record);
				DB_modification_logs("offhours");
				return $id;
			}
			else
			{
				$this->db->insert($this->tblName, $record);	
				$id = $this->db->insert_id();
				DB_modification_logs("offhours");
				return $id;
			}
		} // end save_user
						
		function getDetailByID($id)
		{
		  $id = (int)$id;	
		  $sql = "SELECT 
		  			id, date_format(off_start_time, '%H:%i') AS off_start_time, date_format(off_end_time, '%H:%i') AS off_end_time, skill_id, play_file, ext,
					sat, sun, mon, tue, wed, thu, fri, timezone
		  			 FROM " . $this->tblName . " WHERE id = ".$id;
		  return $this->db->query($sql)->row_array();
		}
		
		function getListingData($GET, $start, $offset = 20)
		{
 			$where = " WHERE 1=1 ";
			if( isset($GET['skill_id']) && trim($GET['skill_id']) != '' )
			{
				$where  .= " AND skill_id = '".trim($this->db->escape($GET['skill_id']),"'")."' ";	
			}
			
			$LIMIT = "LIMIT $start ,  $offset ";
			$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM " . $this->tblName . " {$where} ";
			$results = $this->db->query($sql)->result();	
			$total_record = $this->common_model->get_found_rows();
			
			return array('results' => $results, 'total_record' => $total_record);
		}
		
  }
?>